-
Notifications
You must be signed in to change notification settings - Fork 89
Samples-as-a-tests #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Samples-as-a-tests #119
Conversation
🎉 Snyk checks have passed. No issues have been found so far.✅ security/snyk check is complete. No issues have been found. (View Details) ✅ license/snyk check is complete. No issues have been found. (View Details) |
|
|
||
| // snippet.uuid_metadata_operations | ||
| try { | ||
| $result = $user->setUUIDMetadata() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I other place you used:
$admin->setUuidMetadata()
Is this desired ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PHP's function names are case insensitive. this though should be written with uppercase uuid
examples/AccessManager.php
Outdated
| } | ||
|
|
||
| // Helper function to safely execute operations (deprecated - using direct try/catch now) | ||
| function safeTest($callable, $description) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this method needed? Where it is used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope. probably leftover from copypaste
|
|
||
| class AppContextTest extends TestCase | ||
| { | ||
| public function testExamples(): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this name be more descriptive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a test for examples. how much descriptive a single method name in pretty much self explanatory class should be?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe testAppContextCodeSnippets ?
examples/AppContext.php
Outdated
| $subscribeKey = getenv('SUBSCRIBE_KEY') ?: 'demo'; | ||
|
|
||
| $config = new PNConfiguration(); | ||
| $config->setSubscribeKey(getenv('SUBSCRIBE_KEY', 'demo')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not to pass $publishKey variable here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will fix
| ->profileUrl($user['profileUrl']) | ||
| ->custom($user['custom']) | ||
| ->sync(); | ||
| assert($setUserMetadataResult->getId()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about: "By default, PHP compiles out assert() calls unless you enable zend.assertions=1 and assert.exception=1. In a typical CLI script they won’t even run, so you’ll never know if one failed."
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I've found in docs and on php.watch symbols history the default for zend.assertions is 1 so they are by default enabled.
| return random_bytes(static::IV_LENGTH); | ||
| } | ||
|
|
||
| public function getCipherKey($cipherKey = null): string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't be type-hinted?
| @@ -41,17 +41,17 @@ public function encrypt(string $text, ?string $cipherKey = null): CryptoPayload | |||
| { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In getSecret method is this required to check:
!is_null($cipherKey)
if method signature enforce cipherKey being not null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably redundant, but not the scope of this task.
| return new static( | ||
| [ | ||
| LegacyCryptor::CRYPTOR_ID => new LegacyCryptor($cipherKey, $useRandomIV), | ||
| AesCbcCryptor::CRYPTOR_ID => new AesCbcCryptor($cipherKey), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of:
aesCbcCryptor::CRYPTOR_ID
shouldn't be:
AesCbcCryptor::CRYPTOR_ID
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will fix
| @@ -193,7 +193,7 @@ protected function customParams() | |||
| } | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this ok for buildData method to return null when signature declare return type as string ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the type in comment is just a hint for compatibility with parent IIRC
| @@ -139,4 +171,361 @@ public function testThrowErrorOnNoFileFound(): void | |||
| $this->expectException(PubNubServerException::class); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In testThrowErrorOnMalformedResponse
there is
$pubnub->setClient($client);
and
$this->pubnub->setClient($client);
Are those two needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$this->pubnub->setClient($client); this one was not needed
This adds a lot of samples. Improves testing and coverage